package org.dormi.learn.product.domain.product;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import lombok.Getter;
import org.dormi.learn.product.domain.product.repo.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 模块的依赖项. 它设计为:
 * - 模块所有的依赖全部放这里
 * - 外部可以对这个类进行注入(spring, guice)
 * <p>
 * 这个类有点奇怪, singleton但是却又公开constructor
 * why:
 * 核心业务代码, 不依赖框架
 *
 * @author : dormi330
 * @version : 1.0
 */
@Getter
@Singleton
@Component
public class ModuleDependency {

    private ProductRepository productRepository;

    @Inject
    @Autowired
    public ModuleDependency(ProductRepository productRepository) {
        this.productRepository = productRepository;
        if (instance == null) {
            instance = this;
        }
    }

    // === singleton ===
    // === singleton ===
    // === singleton ===
    private static ModuleDependency instance;

    public static ModuleDependency instance() {
        return instance;
    }

}
